package com.aiobc.business.dataInfo.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aiobc.common.log.annotation.Log;
import com.aiobc.common.log.enums.BusinessType;
import com.aiobc.common.security.annotation.PreAuthorize;
import com.aiobc.business.dataInfo.domain.DataInfo;
import com.aiobc.business.dataInfo.service.IDataInfoService;
import com.aiobc.common.core.web.controller.BaseController;
import com.aiobc.common.core.web.domain.AjaxResult;
import com.aiobc.common.core.utils.poi.ExcelUtil;
import com.aiobc.common.core.web.page.TableDataInfo;

/**
 * 数据信息Controller
 * 
 * @author ruoyi
 * @date 2021-10-22
 */
@RestController
@RequestMapping("/dataInfo")
public class DataInfoController extends BaseController
{
    @Autowired
    private IDataInfoService dataInfoService;

    /**
     * 查询数据信息列表
     */
    @PreAuthorize(hasPermi = "business :info:list")
    @GetMapping("/list")
    public TableDataInfo list(DataInfo dataInfo)
    {
        startPage();
        List<DataInfo> list = dataInfoService.selectDataInfoList(dataInfo);
        return getDataTable(list);
    }

    /**
     * 导出数据信息列表
     */
    @PreAuthorize(hasPermi = "business :info:export")
    @Log(title = "数据信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataInfo dataInfo) throws IOException
    {
        List<DataInfo> list = dataInfoService.selectDataInfoList(dataInfo);
        ExcelUtil<DataInfo> util = new ExcelUtil<DataInfo>(DataInfo.class);
        util.exportExcel(response, list, "数据信息数据");
    }

    /**
     * 获取数据信息详细信息
     */
    @PreAuthorize(hasPermi = "business :info:query")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") String dataId)
    {
        return AjaxResult.success(dataInfoService.selectDataInfoByDataId(dataId));
    }

    /**
     * 新增数据信息
     */
    @PreAuthorize(hasPermi = "business :info:add")
    @Log(title = "数据信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataInfo dataInfo)
    {
        return toAjax(dataInfoService.insertDataInfo(dataInfo));
    }

    /**
     * 修改数据信息
     */
    @PreAuthorize(hasPermi = "business :info:edit")
    @Log(title = "数据信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataInfo dataInfo)
    {
        return toAjax(dataInfoService.updateDataInfo(dataInfo));
    }

    /**
     * 删除数据信息
     */
    @PreAuthorize(hasPermi = "business :info:remove")
    @Log(title = "数据信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable String[] dataIds)
    {
        return toAjax(dataInfoService.deleteDataInfoByDataIds(dataIds));
    }
}
